//
//  LoginController.m
//  APP_login
//
//  Created by edz on 7/7/21.
//  Copyright © 2021 baicai. All rights reserved.
//

#import "TabBarViewController.h"
#import "HomePageVC.h"
#import "AttentionVC.h"
#import "MoreVC.h"
#import "NewsVC.h"
#import "PersonalVC.h"
#import "CustomNavigtionController.h"

@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //分栏图标大小
    CGSize iconSize = CGSizeMake(30, 30);
//    self.tabBarController.tabBar.translucent = NO;
//    [[UITabBar appearance] setShadowImage:[UIImage new]];
    
    UIImage *homeIcon = [UIImage imageNamed:@"home(1)"];
    UIImage *homeIcon1 = [UIImage imageNamed:@"home"];
    HomePageVC * homePage = [[HomePageVC alloc] init];
    UITabBarItem *homeTabBarButton = [[UITabBarItem alloc] initWithTitle:@"首页" image:[self scaleToSize:homeIcon size:iconSize] selectedImage:[self scaleToSize:homeIcon1 size:iconSize]];
    homePage.tabBarItem = homeTabBarButton;
    CustomNavigtionController *home = [[CustomNavigtionController alloc] initWithRootViewController: homePage];
    
    AttentionVC *attentionPage = [[AttentionVC alloc] init];
    UIImage *attentionIcon = [UIImage imageNamed:@"attention(1)"];
    UIImage *attentionIcon1 = [UIImage imageNamed:@"attention(2)"];
    UITabBarItem *attentionTabBarbutton = [[UITabBarItem alloc] initWithTitle:@"关注" image:[self scaleToSize:attentionIcon size:iconSize] selectedImage:[self scaleToSize:attentionIcon1 size:iconSize]];
    attentionPage.tabBarItem = attentionTabBarbutton;
    CustomNavigtionController *attention = [[CustomNavigtionController alloc] initWithRootViewController: attentionPage];
    
    
    MoreVC *morePage = [[MoreVC alloc] init];
    UIImage *moreIcon = [UIImage imageNamed:@"more(2)"];
    UIImage *moreIcon1 = [UIImage imageNamed:@"more(1)"];
    UITabBarItem *moreTabBarbutton = [[UITabBarItem alloc] initWithTitle:@"更多" image:[self scaleToSize:moreIcon size:iconSize] selectedImage:[self scaleToSize:moreIcon1 size:iconSize]];
    morePage.tabBarItem = moreTabBarbutton;
    CustomNavigtionController *more = [[CustomNavigtionController alloc] initWithRootViewController: morePage];
    
    NewsVC *newsPage = [[NewsVC alloc] init];
    UIImage *newsIcon = [UIImage imageNamed:@"message(1)"];
    UIImage *newsIcon1 = [UIImage imageNamed:@"message"];
    UITabBarItem *newsTabBarbutton = [[UITabBarItem alloc] initWithTitle:@"消息" image:[self scaleToSize:newsIcon size:iconSize] selectedImage:[self scaleToSize:newsIcon1 size:iconSize]];
    newsPage.tabBarItem = newsTabBarbutton;
    CustomNavigtionController *news = [[CustomNavigtionController alloc] initWithRootViewController: newsPage];
    
    PersonalVC *personalPage = [[PersonalVC alloc] init];
    UIImage *personalIcon = [UIImage imageNamed:@"my(1)"];
    UIImage *personalIcon1 = [UIImage imageNamed:@"my"];
    UITabBarItem *personalTabBarbutton = [[UITabBarItem alloc] initWithTitle:@"我的" image:[self scaleToSize:personalIcon size:iconSize] selectedImage:[self scaleToSize:personalIcon1 size:iconSize]];
    personalPage.tabBarItem = personalTabBarbutton;
    CustomNavigtionController *personal = [[CustomNavigtionController alloc] initWithRootViewController: personalPage];
    
    self.viewControllers = [NSArray arrayWithObjects:home, attention, more, news, personal,  nil];
    self.selectedIndex = 3;
    self.modalPresentationStyle = 0;
    // Do any additional setup after loading the view.
}

- (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{
     // 创建一个bitmap的context
     // 并把它设置成为当前正在使用的context
     UIGraphicsBeginImageContext(size);
     // 绘制改变大小的图片
     [img drawInRect:CGRectMake(0, 0, size.width, size.height)];
     // 从当前context中创建一个改变大小后的图片
     UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
     // 使当前的context出堆栈
     UIGraphicsEndImageContext();
     // 返回新的改变大小后的图片
     return scaledImage;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
